﻿<#*********************************************************************

 This script will delete all content databases without deleting the 
 web applications.
 
 This is useful when you want to rehearse backup and restore repeatedly
 without having to recreate the web applications, re-deploy solutions,
 create AAMs, etc.
 
**********************************************************************#>

Write-Host ("   Deleting content databases ({0})..." -f [DateTime]::Now.ToString())

if ((Get-PSSnapin -Name  Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) 
{ 
    Add-PsSnapin  Microsoft.SharePoint.PowerShell 
}

$config = [xml](Get-Content Upgrade.xml)

foreach($webApp in $config.Settings.WebApplications.WebApplication)
{
	foreach($contentDb in $webApp.ContentDatabases.ContentDatabase)
	{
		if($contentDb -ne $null)
		{
			Write-Host ("      Deleting content database '{0}' ({1})." -f $contentDb, [DateTime]::Now.ToString())
			Remove-SPContentDatabase -Identity $contentDb
		}
	}
}
